package com.along.currentlimiting.rateLimiter.controller;

import com.along.currentlimiting.rateLimiter.service.RateLimiterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 * @Author: liujinyi
 * @DateTime: 2025/2/17 17:28
 */
@RestController
public class RateLimiterController {

    @Autowired
    private RateLimiterService rateLimiterService;

    @GetMapping("/limited")
    public String limitedEndpoint() {
        if (rateLimiterService.tryAcquire()) {
            return "Request allowed";
        } else {
            return "Request blocked due to rate limiting";
        }
    }
}
